<?php
/**
 * 登陆
 */
class LoginController extends AppController {
	
	/**
	 * 初始化执行
	 *
	 * @see AppController::beforeFilter()
	 */
	public function beforeFilter() {
		parent::beforeFilter ();
	}
	public function index() {
		if ($this->request->isPost ()) {
			$this->loadModel ( "User" );
			
			$email = $this->data ['email'];
			$password = md5 ( $this->data ['password'] );
			
			$UserInfo = $this->User->Login ( $email, $password );
			
			if ($UserInfo) {
				// 登陆成功
				$login_key = Configure::read ( "login_key" );
				
				$hash = md5 ( $UserInfo ['User'] ['uid'] . $this->data ['password'] . $login_key );
				$this->Cookie->write ( 'uid', $UserInfo ['User'] ['uid'] );
				$this->Cookie->write ( 'email', $UserInfo ['User'] ['email'] );
				$this->Cookie->write ( 'hash', $hash );
				
				$this->flash ( '登陆成功!', '/', 1250 );
				return true;
			} else {
				$this->flash ( '账号或密码错误，登陆失败!', '/login/', 1250 );
				return false;
			}
		} else {
			$this->set ( 'title_for_layout', '登陆 - 女人集市' );
			
			// 加载css文件
			$this->set ( 'cssList', array (
					'reg.css' 
			) );
			
			// 加载js文件
			$this->set ( 'scriptList', array (
					'login.js' 
			) );
		}
	}
	/**
	 * 新浪
	 */
	public function sina() {
		$this->autoRender = false;
	}
	/**
	 * QQ登陆
	 */
	public function qq() {
		$this->autoRender = false;
	}
	/**
	 * 腾讯微博
	 */
	public function qweibo() {
		$this->autoRender = false;
	}
	/**
	 * 豆瓣
	 */
	public function douban() {
		$this->autoRender = false;
	}
	
	/**
	 * 退出
	 */
	public function logout() {
		$this->Cookie->destroy ();
		$this->flash ( '退出成功!', '/', 1250 );
		return true;
	}
}
?>